﻿<?php
@session_start();

require_once("../../class/mysql.class.php");

  $obj = new Mysql();
  
  $obj -> set_table('user_login');
  $obj -> set_colone("(`*`)");
  $obj -> set_variables(" id_login = '" . $_SESSION["id"] . "' ");
  $user = $obj -> select_enregistrement();
  
if (isset($_REQUEST['id_entree']))
{   
    $id_monnaie = $_POST["id_monnaie"];
    $prix_en_devise = $_POST["prix_en_devise"];
	
	$id_article = addslashes($_REQUEST["ref_article"]); 
	//$type_id = addslashes($_REQUEST["id_type"]; 
	//$emplacement_id = addslashes($_REQUEST["id_emplacement"]; 
	$id_fournisseur = addslashes($_REQUEST["id_fournisseur"]); 
	$quantite = addslashes($_REQUEST["qte"]);  
	$prix = addslashes($_REQUEST["prix"]); 
	// $id_unit_stockage = addslashes($_REQUEST["unit"];
	$id_type_monnaie = addslashes($_REQUEST["type_monnaie"]); 
	$note = addslashes($_REQUEST["comment"]); 
	$id_user = $user['id_login'];
	
	$reqEntree = "Select id_article, qte from `st_attr_entree` WHERE id_entree='".$_REQUEST['id_entree']."'";
	$resultQteEntree = mysql_query($reqEntree);
	$rowQteEntree = mysql_fetch_array($resultQteEntree);
	
	$QteEntree = $rowQteEntree['qte'];
	$id_art = $rowQteEntree['id_article'];
	
	$reqQteStock= "Select Quantite from `st_article` WHERE id_article='".$id_art."'";
	$resultQteStock = mysql_query($reqQteStock);
	$rowQteStock = mysql_fetch_array($resultQteStock);
	
	$QteStock=$rowQteStock['Quantite'];	
	$QteFinal = $QteStock - $QteEntree + $quantite;
	
	
	
	echo	$sql ="UPDATE `st_attr_entree` SET id_fournisseur='".$id_fournisseur."', qte='".$quantite."',
		prix='".$prix."', id_devise='".$id_monnaie."', note='".$note."', date_add = '".$_REQUEST['dateAdd']."',
		last_modif='".date('Y-m-d')."', last_user_modif='".$id_user."', prix_en_devise ='".$prix_en_devise."'	WHERE id_entree='".$_REQUEST['id_entree']."'";
		
		$obj = new Mysql ();
		if(mysql_query($sql)){
			$reqInsert = "UPDATE st_article SET Quantite='".$QteFinal."' WHERE id_article='".$id_art."'";
				mysql_query($reqInsert);
		}
		
	
	header('location:../../view_list_entree_for_product.php?action=updated&id_article='.$id_art.'&page=list_entree');
}
